<template>
	<view class="page">
		<!-- <TInput label="救援队名" type="text" v-model="rescue_id" /> -->
		<view class="btn" @click="send()">开始匹配</view>
	</view>
</template>

<script>
	import TInput from '../../../components/inputItem/input.vue'
	import {
		startLocation,
		startActivity
	} from '../../../network/me.js'
	export default {
		components: {
			TInput
		},
		data() {
			return {
				rescue_id: '',
				station_id: ''
			};
		},
		async onLoad(options) {
			this.lost_id = options.lost_id
			this.station_id = options.station_id
			console.log(options)
		},
		methods: {
			async send() {
				const location = await uni.getLocation()
				const res1 = await startActivity({
					lost_id: this.lost_id,
					lng: location[1].longitude,
					lat: location[1].latitude,
					station_id: this.station_id
				})
				if (!res1.flag) return
				
				
				// 下面不需要了
				
				// clearInterval(this.$store.state.timer)
				// // 轮询一个接口，直到返回true
				// uni.showLoading({
				// 	title: '匹配中,请稍后'
				// })
				// let timeId = setInterval(async () => {
				// 		const res2 = await startLocation()
				// 		console.log(res2)
				// 		if (res2.flag) {
				// 			console.log(res2.flag,  '成功了')
				// 			clearInterval(timeId)
				// 			uni.hideLoading()
				// 			uni.showToast({
				// 				title: '匹配成功'
				// 			})
				// 			uni.showToast({
				// 				title: '你有新任务',
				// 				icon: 'none'
				// 			})
				// 			// 修改状态
				// 			uni.setStorageSync('lostTarget', JSON.stringify(res2))
				// 			store.commit('setLocationStatus', 1)
				// 			uni.setStorageSync('activity', true)
				// 			setTimeout(uni.navigateBack, 1500)
				// 		}
				// }, 5000)

			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #FFFFFF;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		
		.btn {
			width: 100px;
			height: 100px;
			line-height: 100px;
			margin: -30px auto 0;
			background-color: #1CBAB6;
			color: white;
			text-align: center;
			border-radius: 50%;
			cursor: pointer;

			&:active {
				background-color: #999999;
				color: #333333;
			}
		}
	}
</style>
